﻿using System;
using System.Net;
using System.Web;
using AppCommon;
using Controller;
using Model;

public partial class ACPanel_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Cookies["VYCTravel"] != null)
            {
                Response.Redirect("~/ACPanel/HomeAdmin.aspx");
            }            
        }
    }

    public void CheckCookie(string u, string pwh)
    {
        var user = new ModelVYC17();
        var passHash = pwh;
        user.UserName = u;
        user.PasswordHash = passHash;

        var controller = new VYC17Controller();
        var listUser = controller.CheckLogin(user);

        if (listUser.Count <= 0)
        {
            Response.Redirect("~/ACPanel/HomeAdmin.aspx");
        }
    }

    public static string GetIpAddress()  // Get IP Address
    {
        string ip = "";
        IPHostEntry ipEntry = Dns.GetHostEntry(GetCompCode());
        IPAddress[] addr = ipEntry.AddressList;
        ip = addr[2].ToString();
        return ip;
    }
    public static string GetCompCode()  // Get Computer Name
    {
        string strHostName = "";
        strHostName = Dns.GetHostName();
        return strHostName;
    }
    protected string GetPublicIP()
    {
        string visitorsIpAddr = string.Empty;
        if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
        {
            visitorsIpAddr = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
        }
        else if (!string.IsNullOrEmpty(HttpContext.Current.Request.UserHostAddress))
        {
            visitorsIpAddr = HttpContext.Current.Request.UserHostAddress;
        }
        return visitorsIpAddr;
    }
}